# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=coin-or-osi
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.108.11
pkgrel=1
pkgdesc="COIN-OR Open Solver Interface. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/coin-or/Osi'
msys2_references=(
  'archlinux: coin-or-osi'
)
license=('spdx:EPL-2.0')
groups=("${MINGW_PACKAGE_PREFIX}-coin-or")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-coin-or-coinutils")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-coin-or-buildtools")
source=("${url}/archive/releases/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1063b6a057e80222e2ede3ef0c73c0c54697e0fee1d913e2bef530310c13a670')

prepare() {
  cp -r ${MINGW_PREFIX}/share/coin-or-buildtools/BuildTools Osi-releases-${pkgver}/Osi

  cd Osi-releases-${pkgver}/Osi

  ACLOCAL="aclocal -I${srcdir}/Osi-releases-${pkgver}/Osi/BuildTools" \
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  export lt_cv_deplibs_check_method='pass_all'

  CXXFLAGS+=" -Wno-register" \
  ../"Osi-releases-${pkgver}"/Osi/configure \
    --prefix="${MINGW_PREFIX}" \
    --enable-shared \
    --disable-static \
    --enable-dependency-linking \
    ac_cv_c_compiler_gnu=yes

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/Osi-releases-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
